var amapFile = require('../../libs/amap-wx.js');

Page({
  data: {
    keywords:"",
    tips: {},
    pageFrom : ''
  },
  onLoad: function (e) {
    console.log(e.pageFrom)
    this.setData({
      pageFrom : e.pageFrom
    })
  },
  bindInput: function (e) {
    var that = this;
    var keywords = e.detail.value;
    var myAmapFun = new amapFile.AMapWX({ key: '6d8c96af600990899b4760f7d172f17d' });
    console.log(keywords)
    if(keywords == ""){
      this.setData({
        show:false
      })
    }
    myAmapFun.getInputtips({
      keywords: keywords,
      location: '',
      success: function (res) {
        if (res && res.tips) {
          console.log(res)
          var addressList = [];
          that.setData({
            show: true,
            keywords: keywords,
            tips: res.tips
          });
        }
      }
    })
    
  },
  bindSearch: function (e) {
    var location = e.target.dataset.location;
    var name = e.target.dataset.name;
    if (typeof location == "object" || typeof location == "undefined"){
      wx.showToast({
        title: '请选择详细的地址',
        icon:'none'
      })
    }else{
      wx.setStorageSync('a_a_locatin', location);
      wx.setStorageSync('a_a_name', name);
      if (this.data.pageFrom == "change"){
        // wx.redirectTo({
        //   url: '../chaneMyaddress/chaneMyaddress?pageFrom=' + this.data.pageFrom
        // })
        let pages = getCurrentPages();//当前页面
        let prevPage = pages[pages.length - 2];//上一页面
        prevPage.setData({//直接给上移页面赋值
          locationName: name,
          pageFrom: this.data.pageFrom
        });
        wx.navigateBack({//返回
          delta: 1
        })
      }else{
        let pages = getCurrentPages();//当前页面
        let prevPage = pages[pages.length - 2];//上一页面
        prevPage.setData({//直接给上移页面赋值
         
          pageFrom: this.data.pageFrom
        });
        // wx.redirectTo({
        //   url: '../addAddress/addAddress?pageFrom=' + this.data.pageFrom
        // })
        wx.navigateBack({//返回
          delta: 1
        })
      }
     
    }
  },
  back(){
    wx.redirectTo({
      url: '../addAddress/addAddress?pageFrom=' + this.data.pageFrom
    })
  }
})